import { TaskExecutor, TaskExecutorConfig } from './TaskExecutor';
import { TaskQueryService } from './TaskQueryService';
import { TaskSubmitter } from './TaskSubmitter';

export class TaskSystem<T = any> {
    private readonly executor: TaskExecutor;
    public readonly queryService: TaskQueryService<T>;
    public readonly submitter: TaskSubmitter<T>;

    constructor(config: Partial<TaskExecutorConfig> = {}) {
        this.executor = new TaskExecutor(config);
        this.queryService = new TaskQueryService(this.executor);
        this.submitter = new TaskSubmitter(this.executor);
    }

    /**
     * 创建任务系统实例
     */
    static create<T = any>(config: Partial<TaskExecutorConfig> = {}): TaskSystem<T> {
        return new TaskSystem<T>(config);
    }

    /**
     * 销毁任务系统
     */
    public destroy(): void {
        this.queryService.destroy();
        this.submitter.destroy();
        this.executor.destroy();
    }
}
